package fule.com.playandroidkotlin.ui.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerAdapter
import fule.com.playandroidkotlin.ui.fragment.KnowledgeFragment
import fule.com.playandroidkotlin.ui.model.ChildrenBean
import fule.com.playandroidkotlin.ui.model.KnowledgeModel

/**
 * Created by njb on 2018/5/10.
 */
class KnowledgePagerAdapter(val list: List<ChildrenBean>, fm: FragmentManager) : FragmentPagerAdapter(fm) {

    private val fragments = mutableListOf<Fragment>()

    init {
        list.forEach {
            fragments.add(KnowledgeFragment.getInstance(it.id))
        }
    }

    override fun getItem(position: Int): Fragment = fragments[position]

    override fun getCount(): Int = list.size

    override fun getPageTitle(position: Int): CharSequence? = list[position].name

    override fun getItemPosition(`object`: Any): Int = PagerAdapter.POSITION_NONE
}